package au.com.evoCoach.domain;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

@Entity
public class Team
{
	private Integer id;
	private String teamName;
	private League league;
	private List<Coach> coaches;
	
	@Id
	@GeneratedValue
	@Column
	public Integer getId() {
		return id;
	}
	
	public void setId(final Integer id) {
		this.id = id;
	}

	@Column
	public String getTeamName() {
		return teamName;
	}

	public void setTeamName(String surname) {
		this.teamName = surname;
	}
	
	@OneToOne(cascade=CascadeType.ALL)
    @JoinColumn(name="leagueId")
	public League getLeague() {
		return league;
	}

	public void setLeague(League league) {
		this.league = league;
	}
	
	@OneToMany
	@JoinTable(name = "Coach", joinColumns = { @JoinColumn(name = "coachId") }, inverseJoinColumns = { @JoinColumn(name = "teamId") }) 
	public List<Coach> getCoaches() {
		return coaches;
	}

	public void setCoaches(List<Coach> coaches) {
		this.coaches = coaches;
	}

	@Override
	public boolean equals(Object obj) {
		// TODO Auto-generated method stub
		if (obj instanceof Team) {
			return ((Team) obj).getId().equals(getId());
		}
		
		return false;
	}
	
}
